/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2022-06-21 15:29:15
 * @LastEditors: TT
 * @LastEditTime: 2022-06-22 14:53:50
 */

import 'package:flutter/material.dart';
import 'package:hzy_normal_widget/hzy_normal_widget.dart';
import 'package:hzy_template/utils/common_sp_util.dart';
import 'package:hzy_template/utils/theme_tool.dart';
import '../../../components/common_index.dart';

class MyThemeC extends CommonGetXController {
  var switchValue = false.obs;

  var selectIndex = 2.obs;
  @override
  void onInit() {
    super.onInit();
    configlocaltheme();
  }

  /// 配置本地主题配置
  configlocaltheme() {
    ThemeMode themeMode = ThemeTool.getlocalprofileaboutThemeModel();
    if (themeMode == ThemeMode.system) {
      switchValue.value = true;
    } else {
      switchValue.value = false;
      if (themeMode == ThemeMode.light) {
        selectIndex.value = 2;
      } else if (themeMode == ThemeMode.dark) {
        selectIndex.value = 3;
      }
    }
  }

  /// 点击开关 回调
  configSwitchOnchanged(bool value) {
    switchValue.value = value;
    if (value) {
      CommonSpUtil.saveThemeType(type: 2);
    } else {
      CommonSpUtil.saveThemeType(type: 0);
      selectIndex.value = 2;
    }
    ThemeTool.changeTheme();
  }

  tapdarkitem({required int index}) {
    selectIndex.value = index;
    int type = 0;
    if (index == 2) {
      type = 0;
    } else if (index == 3) {
      type = 1;
    }
    CommonSpUtil.saveThemeType(type: type);
    ThemeTool.changeTheme();
  }
}
